package com.javasm.crm.controller.gift;


import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.GiftInfoCriteria;
import com.javasm.crm.domin.entity.gift.BindGiftList;
import com.javasm.crm.domin.entity.gift.BindGoodlist;
import com.javasm.crm.domin.entity.gift.GiftBindVo;
import com.javasm.crm.domin.entity.gift.GiftType;
import com.javasm.crm.mapper.giftmapper.GiftBindListMapper;
import com.javasm.crm.mapper.giftmapper.GoodsBindListMapper;
import com.javasm.crm.service.giftservice.GiftBindService;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whl
 * @since 2021-07-16
 */
@RestController
@RequestMapping("GiftBind")
@Api(value = "GiftBindController", description = "赠品捆绑管理")
public class GiftBindController {

	@Autowired
	GiftBindService giftBindService;

	@Autowired
	GoodsBindListMapper goodsBindListMapper;
	@Autowired
	GiftBindListMapper giftBindListMapper;

	@GetMapping("getGiftBind")
	@ApiOperation(value = "条件查询", notes = "条件查询")
	public AxiosResult<PageResult<GiftBindVo>> getGoods(GiftInfoCriteria giftInfoCriteria) {
		PageResult<GiftBindVo> giftVoPageResult = giftBindService.searchGiftBindByCriteria(giftInfoCriteria);
		return AxiosResult.success(giftVoPageResult);
	}

	@DeleteMapping("deleteBindById/{giftBindid}")
	@ApiOperation(value = "删除", notes = "删除")
	public AxiosResult<Integer> deleteGiftBindById(@PathVariable Integer giftBindid) {
		int deleteById = giftBindService.deleteGiftBindById(giftBindid);
		return BaseController.toAxiosResult(deleteById);
	}

	@GetMapping("getGiftBindListById")
	@ApiOperation(value = "查询赠品绑定列表", notes = "查询赠品绑定列表")
	public AxiosResult<List<GiftBindVo>> getGiftBindListById(GiftInfoCriteria giftInfoCriteria) {
		List<GiftBindVo> giftBindListById = giftBindService.getGiftBindListById(giftInfoCriteria);
		return AxiosResult.success(giftBindListById);
	}

	@GetMapping("getGoodBindListById")
	@ApiOperation(value = "查询商品绑定列表", notes = "查询商品绑定列表")
	public AxiosResult<List<GiftBindVo>> getGoodBindListById(GiftInfoCriteria giftInfoCriteria) {
		List<GiftBindVo> giftgoodListById = giftBindService.getGoodBindListById(giftInfoCriteria);
		return AxiosResult.success(giftgoodListById);
	}


	@DeleteMapping("deleteBindGoodList/{bindId}")
	@ApiOperation(value = "删除", notes = "删除")
	public AxiosResult<Integer> deleteBindGoodList(@PathVariable Integer bindId) {
		System.out.println(bindId);
		int deleteById = goodsBindListMapper.deleteBindGoodList(bindId);
		return BaseController.toAxiosResult(deleteById);
	}

	@DeleteMapping("deleteBindGiftList/{bindId}")
	@ApiOperation(value = "删除", notes = "删除")
	public AxiosResult<Integer> deleteBindGiftList(@PathVariable Integer bindId) {
		System.out.println(bindId);
		int deleteById = giftBindListMapper.deleteBindGiftList(bindId);
		return BaseController.toAxiosResult(deleteById);
	}

	@PostMapping("addBindGiftList")
	@ApiOperation(value = "添加赠品", notes = "添加赠品")
	public AxiosResult<Integer> addBindGiftList(@RequestBody(required = false) BindGiftList bindGiftList) {
		int save = giftBindListMapper.insert(bindGiftList);
		return BaseController.toAxiosResult(save);
	}

	@PostMapping("addBindGoodList")
	@ApiOperation(value = "添加", notes = "添加")
	public AxiosResult<Integer> addBindGoodList(@RequestBody(required = false) BindGoodlist bindGoodList) {
		int save = goodsBindListMapper.insert(bindGoodList);
		return BaseController.toAxiosResult(save);
	}

}
